<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>超级管理员</title>
    <link rel="stylesheet" href="//cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">


</head>
<body>

<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse"
                    data-target="#example-navbar-collapse">
                <span class="sr-only">切换导航</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">贝丁网</a>
        </div>
        <div class="collapse navbar-collapse" id="example-navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="menu-item"><a href="/ua/manager">管理员菜单</a></li>
                <li class="menu-item"><a href="/ua/logout">退出</a></li>
            </ul>
        </div>
    </div>
</nav>


<script src="//cdn.staticfile.org/jquery/2.1.0/jquery.js"></script>
<script src="//cdn.staticfile.org/jquery.form/4.2.2/jquery.form.min.js"></script>


<style>

    .navbar {
        z-index: 100;
    }

    .containerT {
        text-align: center;
        position: absolute;
        top: 60px;
        left: 50%;
        border-radius: 5%;
        background-color: rgba(255, 255, 255, 0.78);
        transform: translate(-50%, 0);
        padding: 20px;
        max-width: 100%;
        width: available;
    }

    body {
        background-color: #e8e9f5
    }



</style>

<div class="containerT">

    <div class="mypanel title active">


        <h4>
            全部管理员
        </h4>

        <table style="width: max-content;" class="table">

            <%--展示当前--%>

            <tbody style="width: max-content;" class="authority-container">

            </tbody>


            <script>

                //获取所有权限并插入

                $.get('/ua/manager/authority/all', function (all) {

                    let ac = $('.authority-container');

                    for (let username in  all) {


                        let l = all[username].length + 1;

                        //首先插入用户名

                        ac.append(' <tr class="name ' + username + '">' +
                            '                <td rowspan=' + l + '>' +
                            '                    <span>' +

                            username +

                            '                    </span>' +
                            '                </td>' +
                            '            </tr>');


                        let ls = all[username];


                        for (let i in ls) {

                            ac.append('  <tr class="authority ' + username + ' ' + ls[i].authority + '">' +

                                '                <td>' + ls[i].name + '</td>' +
                                '                <td>' +
                                '                    <a class="withdraw ' + username + '">撤回</a>' +
                                '                </td>' +
                                '            </tr>');


                            //绑定权限撤回逻辑

                            $('.withdraw.' + username).click(function () {

                                $.post('/ua/manager/authority/withdraw', {
                                    username: username,
                                    authority: ls[i].authority
                                }, function () {

                                    //移除tr
                                    $('.authority.' + username).remove();

                                    if ($('.authority.' + username).length === 0) {
                                        $('.name.' + username).remove();
                                    }


                                });

                            });

                        }


                    }

                })

            </script>

        </table>


    </div>

</div>
<script src="//cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

</body>

</html>